home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_07 / wilde / convutil.h < prev   
C/C++ Source or Header  |  1993-11-27  |  3KB  |  88 lines

  1. /* File:  convutil.h
  2.    Description: Header file for support code
  3.     for the conversion program.
  4. */
  5. #ifndef CONVUTIL_H
  6. #define CONVUTIL_H
  7. #include <string.h>
  8. /* == miscellaneous types and functions ========== */
  9. typedef enum { FALSE, TRUE} BOOLEAN;
  10. /* ---- enumeration of attribute types ----------- */
  11. enum ATTTYPE {
  12.    NAME,
  13.    FILEN,
  14.    LINE,
  15.    UNKNOWN
  16. };
  17. char * makeHeap(char * s);
  18.                           /* copy string s to heap */
  19. BOOLEAN setErrorFile(char * fname);
  20.                 /* set name of error file to fname */
  21. void wrError(int line, int column);
  22.             /* write message error at line, column */
  23. void cleanUp();
  24.                 /* free the current attribute list */
  25. void putInstanceVariable(void);
  26.     /* write Prolog facts for an instance variable */
  27. void putClass(void);
  28.                  /* write Prolog facts for a class */
  29. /* == Attribute class and derived classes =========*/
  30. class Attribute {
  31. protected:
  32.    enum ATTTYPE atType;
  33.                      /* the type of this attribute */
  34. public:
  35.    virtual char * asString(void) = 0;
  36.   /* answer a ptr to a string rep of the attribute */
  37.    void setType(enum ATTTYPE aT) {atType = aT;}
  38.    virtual ~Attribute() {};
  39. };
  40. class StringAttribute : public Attribute {
  41.          /* An Attribute whose value is a C string */
  42.    char * str;
  43. public:
  44.    StringAttribute( char * s)
  45.          { atType = UNKNOWN; str = s;}
  46.    ~StringAttribute() { delete str;}
  47.    virtual char * asString(void) { return str;}
  48. };
  49. class IdAttribute : public Attribute {
  50.    /* An Attribute with 2 parts, eg:               */
  51.    /*   foo::fob::fab::xxxyyzzzz (int *) const     */
  52.    /*   <---scoped name ------->|<-- remainder --> */
  53.    /* The str holds the whole thing.               */
  54.    char * str;
  55.    char * scopedName;
  56. public:
  57.    IdAttribute(char * sname, char * remainder);
  58.        /* construct from scoped name and remainder */
  59.    ~IdAttribute() {
  60.        delete str; delete scopedName;
  61.        }
  62.    char * asString(void) { return str;}
  63.    char * scopedNamePart(void) {return scopedName;}
  64. };
  65. /* = buffer for reading strings, etc. ============ */
  66. #define MAXCOLLECT 10000         /* size of buffer */
  67. void collect(char c);    /* add c to end of buffer */
  68. void collectFirst(char c);
  69.                          /* clear buffer and add c */
  70. char * release();
  71.         /* copy buffer to heap and return the copy */
  72.  
  73. /* ===== simple linked list of attributes ======== */
  74. struct ATTLIST {
  75.     enum ATTTYPE attype;
  76.     Attribute * attrib;            
  77.     struct ATTLIST * next;
  78. };
  79. struct ATTLIST * listAdd(struct ATTLIST * aList,
  80.               enum ATTTYPE aType, Attribute * aData);
  81. struct ATTLIST * listFind(struct ATTLIST * aList,
  82.                                enum ATTTYPE aType);
  83. int listSize(struct ATTLIST *aList);
  84. void listFree(struct ATTLIST *aList);
  85.  
  86. /* == Functions for the global AttribList ======= */
  87. void atAdd(enum ATTTYPE aType, Attribute * aData);
  88. #endif